package com.baosight.sczx.zm.cs.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.zm.cs.domain.ZMCSEngineeringCustomView;

/**
 * <p>Title: ServiceZMCS52.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张小飞
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-1 下午02:13:08  张小飞  Create
 *</pre>
 */
public class ServiceZMCS52 extends ServiceEPBase {
	/**
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS61</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-2-22上午10:24:34 张小飞
	 * </p>
	 *
	*/
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		EiInfo outInfo = super.query(inInfo, "ZMCSWorkingFace.queryProjectDesign", new ZMCSEngineeringCustomView());//初始化工程设计界面视图的数据（工作面）
		outInfo.addBlock(getCategory(true));//工程设计中的视图界面中构造下拉框的显示内容
		return outInfo;
	}

	/**
	 * <p>Function: query</p>
	 * <p>Description: 工程设计的视图界面（customview）的查询方法 </p>
	 * <p>return value: ServiceZMCS61</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-2-22上午10:24:34 张小飞
	 * </p>
	 *
	*/
	@SuppressWarnings("rawtypes")
	@Override
	public EiInfo query(EiInfo inInfo) {
		String category = inInfo.getBlock(EiConstant.queryBlock).getCellStr(0, "fdCategory");
		EiInfo outInfo = null;
		
		if("0".equals(category)){
			
			outInfo = super.query(inInfo, "ZMCSWorkingFace.queryProjectDesign", new ZMCSEngineeringCustomView());
			
		} else if("1".equals(category)){
			
			outInfo = super.query(inInfo, "ZMCSRoadWay.queryProjectDesign", new ZMCSEngineeringCustomView());
			
		} else if("2".equals(category)){
			
			outInfo = super.query(inInfo, "ZMCSOtherDesign.queryProjectDesign", new ZMCSEngineeringCustomView());
			
		} else {//全部
			outInfo = inInfo;
			outInfo.addBlock(EiConstant.resultBlock).addBlockMeta(new ZMCSEngineeringCustomView().eiMetadata);
			
			List resultMap = dao.query("ZMCSWorkingFace.queryProjectDesign", null);
			outInfo.getBlock(EiConstant.resultBlock).addRows(resultMap);
			
			resultMap = dao.query("ZMCSRoadWay.queryProjectDesign", null);
			outInfo.getBlock(EiConstant.resultBlock).addRows(resultMap);
			
			resultMap = dao.query("ZMCSOtherDesign.queryProjectDesign", null);
			outInfo.getBlock(EiConstant.resultBlock).addRows(resultMap);
			
			outInfo.setBlock(getCategory(true));//不加这个，下拉框选中“全部”，点击查询按钮以后，下拉框中的数据项会无法渲染
		}
		
		return outInfo;
	}
	
	/**
	 * <p>Function: getCategory</p>
	 * <p>Description: 工程设计的视图界面customview</p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-2-15下午04:02:00 张小飞
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	private EiBlock getCategory(boolean isAll) {
		EiBlock block = new EiBlock("cmes.cs.projectCategory");

		EiColumn eiColumn = new EiColumn("label");
		eiColumn.setType("C");
		block.addMeta(eiColumn);

		eiColumn = new EiColumn("value");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map> list = new ArrayList<Map>();
		
		Map<String, String> _map;
		if(isAll) {
			_map = new HashMap<String, String>();
			_map.put("value", "");
			_map.put("label", "全部");
			list.add(_map);
		}
		_map = new HashMap<String, String>();
		_map.put("value", "0");
		_map.put("label", "工作面");
		list.add(_map);
		
		_map = new HashMap<String, String>();
		_map.put("value", "1");
		_map.put("label", "巷道");
		list.add(_map);

		_map = new HashMap<String, String>();
		_map.put("value", "2");
		_map.put("label", "其他");
		list.add(_map);
		
		block.setRows(list);
		return block;
	}
}
